package com.shenfa.dao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.Fodder;

/**
 * 素材信息数据库操作类
 * 
 * @author yanglong
 *
 */
@SuppressWarnings("unchecked")
public class FodderDao {

	@Autowired
	private SqlMapClient sqlMapClient;
	
	/**
	 * 根据对象条件查询所有素材列表
	 */
	public List<Fodder>	queryList(Fodder t, int start, int limit){
		List<Fodder> list = null;
		try {
			list = sqlMapClient.queryForList("fodder_manager.getList", t, start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	public List<Fodder>	queryListNo(Fodder t){
		List<Fodder> list = null;
		try {
			list =sqlMapClient.queryForList("fodder_manager.getListNo",t);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	/*
	 * 素材审核
	 */
	public List<Fodder>	queryListsh(Object o, int start, int limit){
		List<Fodder> list = null;
		try {
			list = sqlMapClient.queryForList("fodder_manager.getListsh",o, start, limit);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	public int	queryCountsh(Object o){
		int a;
		try {
			a = (Integer)sqlMapClient.queryForObject("fodder_manager.getCountsh", o);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		return a;
	}
	public int	queryCount(Fodder t){
		int a;
		try {
			a = (Integer)sqlMapClient.queryForObject("fodder_manager.getCount", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		return a;
	}
	
	/**
	 * 添加素材
	 * @param t	素材对象
	 * @return	1成功，0失败
	 */
	public int add(Fodder t){
		try {
			sqlMapClient.insert("fodder_manager.add", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	/**
	 * 修改素材信息
	 * @param t	素材对象
	 * @return	1成功，0失败
	 */
	public int upd(Fodder t){
		try {
			sqlMapClient.update("fodder_manager.upd", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	/**
	 * 素材素材信息
	 * @param t	素材对象
	 * @return	1成功，0失败
	 */
	public int del(Fodder t){
		try {
			sqlMapClient.delete("fodder_manager.del", t);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	/**
	 * 查询预览文件路径
	 * @param id
	 * @return
	 */
	public String show(String id){
		Object obj=null;
		try {
			obj=sqlMapClient.queryForObject("fodder_manager.showfile",id);
	
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		if(null!=obj){
			return obj.toString();
		}
		return null;
	}
}
